package com.woniu.core.service.Impl;

import com.woniu.core.entity.CoreRecommendationRecord;
import com.woniu.core.mapper.CoreRecommendationRecordMapper;
import com.woniu.core.service.CoreRecommendationRecordService;
import com.woniu.finance.entity.Finance;
import com.woniu.finance.service.IFinanceService;
import com.woniu.platform.entity.PlatformRecommendationRecord;
import com.woniu.platform.service.PlatformRecommendationRecordService;
import com.woniu.util.utils.HttpResult;
import com.woniu.util.utils.RequestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CoreRecommendationRecordServiceImpl implements CoreRecommendationRecordService {
    @Autowired
    private CoreRecommendationRecordMapper coreRecommendationRecordMapper;
    @Autowired
    private IFinanceService financeService;

    @Autowired
    private PlatformRecommendationRecordService platformRecommendationRecordService;

    /**
     * 新增核心企业推荐记录
     * @param cordId 核心企业id
     * @param enterpriseName 融资企业名称
     * @return
     */
    @Override
    public HttpResult<?> addCoreRecommendationRecord(String cordId,String enterpriseName) {
        try {
            CoreRecommendationRecord coreRecommendationRecord = new CoreRecommendationRecord();
            coreRecommendationRecord.setCoreId(cordId);
            coreRecommendationRecord.setRecordId(0);
            Finance finance = financeService.findFinanceByName(enterpriseName);
            coreRecommendationRecord.setEnterpriseId(finance.getEnterpriseId());
            int result = coreRecommendationRecordMapper.insert(coreRecommendationRecord);
            if(result > 0){
                return new HttpResult<>().ok();
            }
            return new HttpResult<>().fail();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 修改核心企业推荐记录
     * @param coreRecommendationRecord 需要修改的推荐记录
     * @return
     */
    @Override
    public HttpResult<?> updateCoreRecommendationRecord(CoreRecommendationRecord coreRecommendationRecord) {
        return null;
    }

    /**
     * 删除核心企业推荐记录
     * @param coreRecommendationRecordId 需要删除的推荐记录
     * @return
     */
    @Override
    public HttpResult<?> deleteCoreRecommendationRecord(Integer coreRecommendationRecordId) {
        return null;
    }

    /**
     * 查找核心企业推荐记录
     * @return
     */
    @Override
    public HttpResult<?> deleteCoreRecommendationRecord() {
        return null;
    }

    /**
     * 根据核心企业id查询平台推荐的融资企业
     * @param requestResult
     * @return
     */
    public HttpResult<?> selectRecommendationByCoreId(RequestResult<PlatformRecommendationRecord> requestResult){
        return platformRecommendationRecordService.selectRecommendationByCoreId(requestResult);
    }
}
